﻿using HANS.Log;
using HANS_Base.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HANS_Base.Services
{
   public static class JsonResultDataServices
    {
        public static JsonResultData RunWithTry(this JsonResultData jsonResultEntry, Action<JsonResultData> runMethod)
        {
            try
            {
                runMethod.Invoke(jsonResultEntry);
            }
            catch (Exception ex)
            {
                jsonResultEntry.Success = false;
                jsonResultEntry.AddMessage(ex.Message);
                LogHelper.WriteError($"RunWithTry Error, {System.Web.HttpContext.Current.Request.Url.AbsolutePath}"+ ex.ToString());
            }
            return jsonResultEntry;
        }
    }
}
